import * as THREE from 'three';
import { PhysicsWorld } from '../utils/PhysicsWorld';
import { Projectile } from './Projectile';
import { Explosion } from './Explosion';
import { Debug } from '../utils/Debug';

export class PlayerTank {
  // Three.js 相关
  private scene: THREE.Scene;
  private tankBody: THREE.Object3D;
  private tankTurret: THREE.Object3D;
  private tankBarrel: THREE.Object3D;
  
  // 位置和旋转
  private position: THREE.Vector3;
  private rotation: number = 0;
  private turretRotation: number = 0;
  
  // 物理和碰撞
  private physics: PhysicsWorld;
  private tankCollider: any; // 物理系统碰撞体
  
  // 移动属性
  private originalMoveSpeed: number = 5.0;
  private moveSpeed: number = 5.0;
  private rotationSpeed: number = 2.0;
  private turretRotationSpeed: number = 3.0;
  
  // 射击属性
  private projectiles: Projectile[] = [];
  private lastShotTime: number = 0;
  private originalReloadTime: number = 0.5; // 秒
  private reloadTime: number = 0.5; // 秒
  
  // 玩家属性
  private health: number = 100;
  private maxHealth: number = 100;
  private score: number = 0;
  private energy: number = 100;
  private maxEnergy: number = 100;
  private energyRechargeRate: number = 5; // 每秒恢复的能量
  private alive: boolean = true;
  
  // 摄像机跟随
  private cameraOffset: THREE.Vector3 = new THREE.Vector3(0, 8, -10);
  private cameraTarget: THREE.Vector3 = new THREE.Vector3();
  
  // 坦克颜色
  private tankColor: number = 0x2277cc;
  
  // 输入状态
  private inputKeys: { [key: string]: boolean } = {
    forward: false,
    backward: false,
    left: false,
    right: false,
    turretLeft: false,
    turretRight: false,
    fire: false
  };
  
  // 生命值变化回调
  public onHealthChange?: (health: number) => void;
  
  // 投射物创建回调
  private onProjectileCreated: (projectile: Projectile) => void;
  
  // 增强效果计时器
  private speedBoostTimeout: any = null;
  private firepowerBoostTimeout: any = null;
  
  constructor(
    scene: THREE.Scene, 
    physics: PhysicsWorld,
    loadingManager: THREE.LoadingManager,
    onProjectileCreated: (projectile: Projectile) => void,
    onHealthChange: (health: number) => void
  ) {
    this.scene = scene;
    this.physics = physics;
    this.position = new THREE.Vector3(0, 0.5, 0); // 使用默认初始位置
    this.onHealthChange = onHealthChange;
    this.onProjectileCreated = onProjectileCreated;

    try {
      // 创建坦克模型
      this.createTank();
      
      // 初始化输入处理
      this.setupInputHandlers();
      
      Debug.log('玩家坦克已创建');
    } catch (error) {
      Debug.error(`创建玩家坦克时出错: ${error}`);
      throw error;
    }
  }
  
  private createTank(): void {
    try {
      // 创建坦克主体
      const bodyGeometry = new THREE.BoxGeometry(1.5, 0.6, 2);
      const bodyMaterial = new THREE.MeshStandardMaterial({
        color: this.tankColor,
        metalness: 0.7,
        roughness: 0.3
      });
      
      this.tankBody = new THREE.Mesh(bodyGeometry, bodyMaterial);
      this.tankBody.position.copy(this.position);
      this.tankBody.castShadow = true;
      this.tankBody.receiveShadow = true;
      
      // 创建坦克炮塔
      const turretGeometry = new THREE.CylinderGeometry(0.6, 0.6, 0.5, 8);
      const turretMaterial = new THREE.MeshStandardMaterial({
        color: this.tankColor,
        metalness: 0.7,
        roughness: 0.3
      });
      
      this.tankTurret = new THREE.Mesh(turretGeometry, turretMaterial);
      this.tankTurret.position.y = 0.3 + 0.25;
      this.tankTurret.castShadow = true;
      
      // 创建坦克炮管
      const barrelGeometry = new THREE.CylinderGeometry(0.1, 0.1, 1.2, 8);
      const barrelMaterial = new THREE.MeshStandardMaterial({
        color: 0x111111,
        metalness: 0.8,
        roughness: 0.2
      });
      
      this.tankBarrel = new THREE.Mesh(barrelGeometry, barrelMaterial);
      this.tankBarrel.position.set(0, 0, 0.7);
      this.tankBarrel.rotation.x = Math.PI / 2;
      this.tankBarrel.castShadow = true;
      
      // 组装坦克
      this.tankTurret.add(this.tankBarrel);
      this.tankBody.add(this.tankTurret);
      this.scene.add(this.tankBody);
      
      // 添加物理碰撞体
      this.tankCollider = this.physics.addBoxCollider(
        this.tankBody,
        new THREE.Vector3(1.5, 0.6, 2),
        this.position,
        0,
        'player'
      );

      Debug.log('坦克模型创建成功');
    } catch (error) {
      Debug.error(`创建坦克模型时出错: ${error}`);
      throw error;
    }
  }
  
  public setupInputHandlers(): void {
    // 键盘控制
    window.addEventListener('keydown', (event) => {
      switch (event.key.toLowerCase()) {
        case 'w': this.inputKeys.forward = true; break;
        case 's': this.inputKeys.backward = true; break;
        case 'a': this.inputKeys.left = true; break;
        case 'd': this.inputKeys.right = true; break;
        case 'q': this.inputKeys.turretLeft = true; break;
        case 'e': this.inputKeys.turretRight = true; break;
      }
    });
    
    window.addEventListener('keyup', (event) => {
      switch (event.key.toLowerCase()) {
        case 'w': this.inputKeys.forward = false; break;
        case 's': this.inputKeys.backward = false; break;
        case 'a': this.inputKeys.left = false; break;
        case 'd': this.inputKeys.right = false; break;
        case 'q': this.inputKeys.turretLeft = false; break;
        case 'e': this.inputKeys.turretRight = false; break;
      }
    });
    
    // 鼠标控制
    window.addEventListener('mousemove', (event) => {
      // 根据鼠标位置计算炮塔旋转
      const mouseX = (event.clientX / window.innerWidth) * 2 - 1;
      this.turretRotation = mouseX * Math.PI;
    });
    
    window.addEventListener('mousedown', (event) => {
      if (event.button === 0) { // 左键
        this.inputKeys.fire = true;
      }
    });
    
    window.addEventListener('mouseup', (event) => {
      if (event.button === 0) { // 左键
        this.inputKeys.fire = false;
      }
    });
  }
  
  public update(deltaTime: number, camera?: THREE.Camera): void {
    // 处理输入移动
    this.handleMovement(deltaTime);
    
    // 更新坦克位置
    this.tankBody.position.copy(this.position);
    this.tankBody.rotation.y = this.rotation;
    this.tankTurret.rotation.y = this.turretRotation;
    
    // 更新物理碰撞体
    this.physics.updateCollider(
      this.tankCollider, 
      this.position,
      this.rotation
    );
    
    // 更新射击
    this.handleShooting(deltaTime);
    
    // 更新投射物
    this.updateProjectiles(deltaTime);
    
    // 能量恢复
    this.energy = Math.min(this.maxEnergy, this.energy + this.energyRechargeRate * deltaTime);
    
    // 更新相机位置（如果提供了相机）
    if (camera) {
      this.updateCamera(camera);
    }
  }
  
  private handleMovement(deltaTime: number): void {
    // 计算移动和旋转
    const moveDistance = this.moveSpeed * deltaTime;
    const rotateAmount = this.rotationSpeed * deltaTime;
    
    // 旋转坦克
    if (this.inputKeys.left) {
      this.rotation += rotateAmount;
      // 确保旋转被正确应用到模型
      this.tankBody.rotation.y = this.rotation;
    }
    if (this.inputKeys.right) {
      this.rotation -= rotateAmount;
      // 确保旋转被正确应用到模型
      this.tankBody.rotation.y = this.rotation;
    }
    
    // 旋转炮塔（键盘控制）
    if (this.inputKeys.turretLeft) {
      this.turretRotation += this.turretRotationSpeed * deltaTime;
      // 确保炮塔旋转被正确应用到模型
      this.tankTurret.rotation.y = this.turretRotation;
    }
    if (this.inputKeys.turretRight) {
      this.turretRotation -= this.turretRotationSpeed * deltaTime;
      // 确保炮塔旋转被正确应用到模型
      this.tankTurret.rotation.y = this.turretRotation;
    }
    
    // 计算前进方向
    const forwardVector = new THREE.Vector3(
      Math.sin(this.rotation),
      0,
      Math.cos(this.rotation)
    );
    
    // 前进/后退
    let moved = false;
    
    if (this.inputKeys.forward) {
      const moveVec = forwardVector.clone().multiplyScalar(moveDistance);
      const newPosition = this.position.clone().add(moveVec);
      
      // 检查碰撞，使用debug查看碰撞
      if (!this.physics.checkCollision(newPosition, 1.0, 'player', Debug.isEnabled())) {
        this.position.copy(newPosition);
        moved = true;
      } else {
        // 尝试斜向移动（这有助于绕过障碍物）
        const sideStep = 0.7; // 斜向移动的系数
        
        // 尝试右侧移动
        const rightMoveVec = new THREE.Vector3(
          Math.sin(this.rotation + Math.PI/4) * moveDistance * sideStep,
          0,
          Math.cos(this.rotation + Math.PI/4) * moveDistance * sideStep
        );
        const rightPosition = this.position.clone().add(rightMoveVec);
        
        if (!this.physics.checkCollision(rightPosition, 1.0, 'player')) {
          this.position.copy(rightPosition);
          moved = true;
        } else {
          // 尝试左侧移动
          const leftMoveVec = new THREE.Vector3(
            Math.sin(this.rotation - Math.PI/4) * moveDistance * sideStep,
            0,
            Math.cos(this.rotation - Math.PI/4) * moveDistance * sideStep
          );
          const leftPosition = this.position.clone().add(leftMoveVec);
          
          if (!this.physics.checkCollision(leftPosition, 1.0, 'player')) {
            this.position.copy(leftPosition);
            moved = true;
          }
        }
      }
    }
    
    if (this.inputKeys.backward) {
      const moveVec = forwardVector.clone().multiplyScalar(-moveDistance);
      const newPosition = this.position.clone().add(moveVec);
      
      // 检查碰撞
      if (!this.physics.checkCollision(newPosition, 1.0, 'player', Debug.isEnabled())) {
        this.position.copy(newPosition);
        moved = true;
      } else {
        // 尝试斜向移动
        const sideStep = 0.7;
        
        // 尝试右侧移动
        const rightMoveVec = new THREE.Vector3(
          Math.sin(this.rotation - Math.PI/4) * -moveDistance * sideStep,
          0,
          Math.cos(this.rotation - Math.PI/4) * -moveDistance * sideStep
        );
        const rightPosition = this.position.clone().add(rightMoveVec);
        
        if (!this.physics.checkCollision(rightPosition, 1.0, 'player')) {
          this.position.copy(rightPosition);
          moved = true;
        } else {
          // 尝试左侧移动
          const leftMoveVec = new THREE.Vector3(
            Math.sin(this.rotation + Math.PI/4) * -moveDistance * sideStep,
            0,
            Math.cos(this.rotation + Math.PI/4) * -moveDistance * sideStep
          );
          const leftPosition = this.position.clone().add(leftMoveVec);
          
          if (!this.physics.checkCollision(leftPosition, 1.0, 'player')) {
            this.position.copy(leftPosition);
            moved = true;
          }
        }
      }
    }
    
    if (moved) {
      Debug.log(`坦克移动到：(${this.position.x.toFixed(2)}, ${this.position.y.toFixed(2)}, ${this.position.z.toFixed(2)})`);
    }
  }
  
  private handleShooting(deltaTime: number): void {
    // 检查是否可以射击
    const currentTime = Date.now() / 1000; // 当前时间（秒）
    const timeSinceLastShot = currentTime - this.lastShotTime;
    
    if (this.inputKeys.fire && timeSinceLastShot > this.reloadTime && this.energy >= 10) {
      // 射击
      this.fire();
      
      // 更新最后射击时间
      this.lastShotTime = currentTime;
      
      // 射击消耗能量
      this.energy -= 10;
    }
  }
  
  private fire(): void {
    // 计算射击起始位置和方向
    const barrelTip = new THREE.Vector3(0, 0, 0.6);
    this.tankBarrel.localToWorld(barrelTip);
    
    // 计算子弹方向（与炮管对齐）
    const direction = new THREE.Vector3();
    direction.subVectors(barrelTip, this.tankTurret.getWorldPosition(new THREE.Vector3()));
    direction.normalize();
    
    // 稍微抬高炮弹的起始位置，使其更容易被看到
    barrelTip.y += 0.1;
    
    // 创建子弹，增加速度使轨迹更明显
    const projectile = new Projectile(
      this.scene,
      barrelTip,
      direction,
      'player',
      25, // 伤害
      20  // 降低速度，使轨迹更容易观察
    );
    
    // 添加到投射物数组并通知游戏
    this.projectiles.push(projectile);
    this.onProjectileCreated(projectile);
    
    // 射击音效和视觉效果
    this.createMuzzleFlash(barrelTip);
    
    Debug.log('玩家射击');
  }
  
  private createMuzzleFlash(position: THREE.Vector3): void {
    // 创建一个临时的Group作为容器
    const flashEffects = new THREE.Group();
    this.scene.add(flashEffects);
    
    // 创建一个临时的光源模拟枪口闪光
    const light = new THREE.PointLight(0xffaa44, 3, 4);
    light.position.copy(position);
    flashEffects.add(light);
    
    // 简单的粒子效果
    const particles = new THREE.Group();
    flashEffects.add(particles);
    
    // 添加几个小球代表粒子
    for (let i = 0; i < 5; i++) {
      const geometry = new THREE.SphereGeometry(0.05, 4, 4);
      const material = new THREE.MeshBasicMaterial({
        color: 0xffaa44,
        transparent: true,
        opacity: 0.8
      });
      
      const particle = new THREE.Mesh(geometry, material);
      
      // 随机位置偏移
      particle.position.set(
        position.x + (Math.random() - 0.5) * 0.1,
        position.y + (Math.random() - 0.5) * 0.1,
        position.z + (Math.random() - 0.5) * 0.1
      );
      
      particles.add(particle);
    }
    
    // 短暂显示后移除并清理资源
    setTimeout(() => {
      // 清理所有子物体的资源
      while (flashEffects.children.length > 0) {
        const child = flashEffects.children[0];
        flashEffects.remove(child);
        
        // 处理光源
        if (child instanceof THREE.Light) {
          child.dispose();
        }
        
        // 处理粒子组
        if (child instanceof THREE.Group) {
          while (child.children.length > 0) {
            const particle = child.children[0];
            child.remove(particle);
            
            if (particle instanceof THREE.Mesh) {
              if (particle.geometry) {
                particle.geometry.dispose();
              }
              if (particle.material) {
                if (Array.isArray(particle.material)) {
                  particle.material.forEach(m => m.dispose());
                } else {
                  particle.material.dispose();
                }
              }
            }
          }
        }
      }
      
      // 从场景中移除整个效果组
      this.scene.remove(flashEffects);
    }, 150); // 稍微延长显示时间
  }
  
  private updateProjectiles(deltaTime: number): void {
    // 更新所有活跃的子弹
    for (let i = this.projectiles.length - 1; i >= 0; i--) {
      const projectile = this.projectiles[i];
      
      // 如果子弹不再活跃，从数组中移除
      if (!projectile.update(deltaTime)) {
        this.projectiles.splice(i, 1);
      } else {
        // 检查子弹是否与敌人碰撞
        const enemyHit = this.physics.checkProjectileCollision(
          projectile.getPosition(),
          projectile.getRadius(),
          'enemy'
        );
        
        if (enemyHit) {
          // 创建爆炸效果
          const explosion = new Explosion(
            this.scene,
            projectile.getPosition(),
            0.5 // 小型爆炸
          );
          
          // 处理伤害和分数（由Game类处理）
          
          // 移除子弹
          projectile.dispose();
          this.projectiles.splice(i, 1);
        }
      }
    }
  }
  
  private updateCamera(camera: THREE.Camera): void {
    // 计算目标相机位置（跟随坦克）
    const idealOffset = new THREE.Vector3();
    idealOffset.copy(this.cameraOffset);
    idealOffset.applyAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation);
    idealOffset.add(this.position);
    
    // 平滑过渡到新位置
    camera.position.lerp(idealOffset, 0.1);
    
    // 设置相机观察目标
    this.cameraTarget.copy(this.position);
    this.cameraTarget.y += 1; // 稍微向上看一点
    camera.lookAt(this.cameraTarget);
  }
  
  public getPosition(): THREE.Vector3 {
    return this.position.clone();
  }
  
  public getRotation(): number {
    return this.rotation;
  }
  
  public getTurretRotation(): number {
    return this.turretRotation;
  }
  
  public getHealth(): number {
    return this.health;
  }
  
  public getMaxHealth(): number {
    return this.maxHealth;
  }
  
  public getEnergy(): number {
    return this.energy;
  }
  
  public getMaxEnergy(): number {
    return this.maxEnergy;
  }
  
  public getScore(): number {
    return this.score;
  }
  
  public takeDamage(amount: number): void {
    // 如果已经死亡，不再处理伤害
    if (!this.alive) return;
    
    this.health = Math.max(0, this.health - amount);
    
    // 创建受击效果
    this.createHitEffect();
    
    // 发送生命值变化通知
    if (this.onHealthChange) {
      this.onHealthChange(this.health);
    }
    
    Debug.log(`玩家受到 ${amount} 点伤害，剩余生命值: ${this.health}`);
    
    // 检查是否死亡
    if (this.health <= 0) {
      this.alive = false;
      this.explode();
    }
  }
  
  private createHitEffect(): void {
    // 闪烁坦克主体
    const originalColor = (this.tankBody as THREE.Mesh).material.color.getHex();
    (this.tankBody as THREE.Mesh).material.color.set(0xff0000);
    
    // 恢复原来的颜色
    setTimeout(() => {
      (this.tankBody as THREE.Mesh).material.color.set(originalColor);
    }, 100);
  }
  
  public explode(): void {
    // 创建大型爆炸效果
    new Explosion(
      this.scene,
      this.position.clone(),
      1.5 // 大型爆炸
    );
    
    // 隐藏坦克（但不从场景移除，游戏逻辑可能还需要引用）
    this.tankBody.visible = false;
    
    Debug.log('玩家坦克爆炸');
  }
  
  public respawn(position: THREE.Vector3): void {
    // 重置属性
    this.health = this.maxHealth;
    this.energy = this.maxEnergy;
    this.position.copy(position);
    this.rotation = 0;
    this.turretRotation = 0;
    
    // 显示坦克
    this.tankBody.visible = true;
    this.tankBody.position.copy(this.position);
    this.tankBody.rotation.y = this.rotation;
    this.tankTurret.rotation.y = this.turretRotation;
    
    // 更新碰撞体
    this.physics.updateCollider(
      this.tankCollider,
      this.position,
      this.rotation
    );
    
    Debug.log('玩家坦克重生');
  }
  
  public addScore(points: number): void {
    this.score += points;
    Debug.log(`玩家得分 +${points}，总分: ${this.score}`);
  }
  
  public addEnergy(amount: number): void {
    this.energy = Math.min(this.maxEnergy, this.energy + amount);
    Debug.log(`玩家获得能量 +${amount}，当前能量: ${this.energy}`);
  }
  
  public setMoveSpeed(speed: number): void {
    this.moveSpeed = speed;
  }
  
  public setFireRate(reloadTime: number): void {
    this.reloadTime = reloadTime;
  }
  
  public dispose(): void {
    // 清理投射物
    this.projectiles.forEach(projectile => projectile.dispose());
    this.projectiles = [];
    
    // 从场景中移除坦克
    this.scene.remove(this.tankBody);
    
    // 移除物理碰撞体
    this.physics.removeCollider(this.tankCollider);
    
    // 移除事件监听器
    window.removeEventListener('keydown', this.handleKeyDown);
    window.removeEventListener('keyup', this.handleKeyUp);
    window.removeEventListener('mousemove', this.handleMouseMove);
    window.removeEventListener('mousedown', this.handleMouseDown);
    window.removeEventListener('mouseup', this.handleMouseUp);
    
    Debug.log('玩家坦克资源已清理');
  }
  
  // 事件处理器引用
  private handleKeyDown = (event: KeyboardEvent): void => {
    switch (event.key.toLowerCase()) {
      case 'w': this.inputKeys.forward = true; break;
      case 's': this.inputKeys.backward = true; break;
      case 'a': this.inputKeys.left = true; break;
      case 'd': this.inputKeys.right = true; break;
      case 'q': this.inputKeys.turretLeft = true; break;
      case 'e': this.inputKeys.turretRight = true; break;
    }
  };
  
  private handleKeyUp = (event: KeyboardEvent): void => {
    switch (event.key.toLowerCase()) {
      case 'w': this.inputKeys.forward = false; break;
      case 's': this.inputKeys.backward = false; break;
      case 'a': this.inputKeys.left = false; break;
      case 'd': this.inputKeys.right = false; break;
      case 'q': this.inputKeys.turretLeft = false; break;
      case 'e': this.inputKeys.turretRight = false; break;
    }
  };
  
  private handleMouseMove = (event: MouseEvent): void => {
    const mouseX = (event.clientX / window.innerWidth) * 2 - 1;
    this.turretRotation = mouseX * Math.PI;
  };
  
  private handleMouseDown = (event: MouseEvent): void => {
    if (event.button === 0) { // 左键
      this.inputKeys.fire = true;
    }
  };
  
  private handleMouseUp = (event: MouseEvent): void => {
    if (event.button === 0) { // 左键
      this.inputKeys.fire = false;
    }
  };
  
  /**
   * 重置玩家坦克状态
   */
  public reset(): void {
    // 重置生命值和能量
    this.health = this.maxHealth;
    this.energy = this.maxEnergy;
    
    // 发送生命值变化通知
    if (this.onHealthChange) {
      this.onHealthChange(this.health);
    }
    
    // 重置位置和旋转
    this.position.set(0, 0.5, 0);
    this.rotation = 0;
    this.turretRotation = 0;
    
    // 更新视觉组件
    this.tankBody.position.copy(this.position);
    this.tankBody.rotation.y = this.rotation;
    this.tankTurret.rotation.y = this.turretRotation;
    
    // 更新碰撞器
    this.physics.updateCollider(this.tankCollider, this.position, this.rotation);
    
    // 重置移动速度和射击速度
    this.moveSpeed = this.originalMoveSpeed;
    this.reloadTime = this.originalReloadTime;
    
    // 清除所有强化效果计时器
    if (this.speedBoostTimeout) {
      clearTimeout(this.speedBoostTimeout);
      this.speedBoostTimeout = null;
    }
    
    if (this.firepowerBoostTimeout) {
      clearTimeout(this.firepowerBoostTimeout);
      this.firepowerBoostTimeout = null;
    }
    
    // 重置存活状态
    this.alive = true;
    this.tankBody.visible = true;
    
    Debug.log('玩家坦克已重置');
  }
  
  /**
   * 临时提升移动速度
   */
  public boostSpeed(duration: number = 5000): void {
    // 清除现有的速度提升计时器
    if (this.speedBoostTimeout) {
      clearTimeout(this.speedBoostTimeout);
    }
    
    // 设置新的移动速度
    this.moveSpeed = this.originalMoveSpeed * 1.5;
    
    // 设置计时器恢复原速度
    this.speedBoostTimeout = setTimeout(() => {
      this.moveSpeed = this.originalMoveSpeed;
      Debug.log('速度提升效果已结束');
    }, duration);
    
    Debug.log(`速度已提升至 ${this.moveSpeed.toFixed(1)}，持续 ${duration/1000} 秒`);
  }
  
  /**
   * 临时提升火力（减少射击冷却时间）
   */
  public boostFirepower(duration: number = 5000): void {
    // 清除现有的火力提升计时器
    if (this.firepowerBoostTimeout) {
      clearTimeout(this.firepowerBoostTimeout);
    }
    
    // 减少射击冷却时间
    this.reloadTime = this.originalReloadTime * 0.5;
    
    // 设置计时器恢复原始射击速度
    this.firepowerBoostTimeout = setTimeout(() => {
      this.reloadTime = this.originalReloadTime;
      Debug.log('火力提升效果已结束');
    }, duration);
    
    Debug.log(`火力已提升（射击冷却时间: ${this.reloadTime.toFixed(2)}秒），持续 ${duration/1000} 秒`);
  }
  
  /**
   * 恢复生命值
   */
  public heal(amount: number): void {
    this.health = Math.min(this.maxHealth, this.health + amount);
    
    // 发送生命值变化通知
    if (this.onHealthChange) {
      this.onHealthChange(this.health);
    }
    
    Debug.log(`玩家恢复 ${amount} 点生命值，当前生命: ${this.health}`);
  }
  
  /**
   * 检查坦克是否存活
   */
  public isAlive(): boolean {
    return this.alive;
  }
  
  /**
   * 获取坦克的碰撞体
   */
  public getCollider(): any {
    return this.tankCollider;
  }
} 